package com.Reporte_MasVendidos;


import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
 
public class ImageAdapter_final extends BaseAdapter implements ListAdapter {
 
	public Context context;
    public ArrayList<subTipo> subTipo;
      
 
    public ImageAdapter_final(ArrayList<subTipo> subTipo,Context context) {
    	this.context = context;
        this.subTipo = subTipo;
        for(int i=0; i<subTipo.size();i++){
    		Log.d("url:", subTipo.get(i).getUrl());
    	}
	}

	@Override
    public long getItemId(int position) {
         
        return position;
    }

	@Override
	public int getCount() {
		return subTipo.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return subTipo.get(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView;
        if(convertView==null)
        {
            imageView=new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(190,190));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5,5,5,5);
        }else{
            imageView=(ImageView)convertView;
        }
        try {
        	Log.e("size:", String.valueOf(subTipo.size()));
        	Log.e("url:", subTipo.get(position).getUrl());
			imageView.setImageDrawable((new ImageDownloader().execute(subTipo.get(position).getUrl())).get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        return imageView;
	}
 

 
}